<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>model::linestring</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../index.html" title="Chapter 1. Geometry">
<link rel="up" href="../models.html" title="Models">
<link rel="prev" href="model_d3_point_xyz.html" title="model::d3::point_xyz">
<link rel="next" href="model_polygon.html" title="model::polygon">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="model_d3_point_xyz.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../models.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="model_polygon.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="geometry.reference.models.model_linestring"></a><a class="link" href="model_linestring.html" title="model::linestring">model::linestring</a>
</h4></div></div></div>
<p>
          <a class="indexterm" name="idm45246421444768"></a><a class="indexterm" name="idm45246421444080"></a>
A linestring (named so by OGC) is a collection (default a vector) of points.
        </p>
<h6>
<a name="geometry.reference.models.model_linestring.h0"></a>
          <span class="phrase"><a name="geometry.reference.models.model_linestring.model_of"></a></span><a class="link" href="model_linestring.html#geometry.reference.models.model_linestring.model_of">Model of</a>
        </h6>
<p>
          <a class="link" href="../concepts/concept_linestring.html" title="Linestring Concept">Linestring
          Concept</a>
        </p>
<h6>
<a name="geometry.reference.models.model_linestring.h1"></a>
          <span class="phrase"><a name="geometry.reference.models.model_linestring.synopsis"></a></span><a class="link" href="model_linestring.html#geometry.reference.models.model_linestring.synopsis">Synopsis</a>
        </h6>
<p>
</p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Point</span><span class="special">,</span> <span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span><span class="special">,</span> <span class="keyword">typename</span> <span class="special">&gt;</span> <span class="keyword">class</span> <span class="identifier">Container</span><span class="special">,</span> <span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">typename</span> <span class="special">&gt;</span> <span class="keyword">class</span> <span class="identifier">Allocator</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">model</span><span class="special">::</span><span class="identifier">linestring</span>
      <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">Container</span><span class="special">&lt;</span> <span class="identifier">Point</span><span class="special">,</span> <span class="identifier">Allocator</span><span class="special">&lt;</span> <span class="identifier">Point</span> <span class="special">&gt;</span> <span class="special">&gt;</span>
<span class="special">{</span>
  <span class="comment">// ...</span>
<span class="special">};</span>
</pre>
<p>
        </p>
<h6>
<a name="geometry.reference.models.model_linestring.h2"></a>
          <span class="phrase"><a name="geometry.reference.models.model_linestring.template_parameter_s_"></a></span><a class="link" href="model_linestring.html#geometry.reference.models.model_linestring.template_parameter_s_">Template
          parameter(s)</a>
        </h6>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                  <p>
                    Parameter
                  </p>
                </th>
<th>
                  <p>
                    Default
                  </p>
                </th>
<th>
                  <p>
                    Description
                  </p>
                </th>
</tr></thead>
<tbody>
<tr>
<td>
                  <p>
                    typename Point
                  </p>
                </td>
<td>
                </td>
<td>
                  <p>
                    Any type fulfilling a Point Concept
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    template&lt; typename, typename &gt; class Container
                  </p>
                </td>
<td>
                  <p>
                    std::vector
                  </p>
                </td>
<td>
                  <p>
                    container type, for example std::vector, std::deque
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    template&lt; typename &gt; class Allocator
                  </p>
                </td>
<td>
                  <p>
                    std::allocator
                  </p>
                </td>
<td>
                  <p>
                    container-allocator-type
                  </p>
                </td>
</tr>
</tbody>
</table></div>
<h6>
<a name="geometry.reference.models.model_linestring.h3"></a>
          <span class="phrase"><a name="geometry.reference.models.model_linestring.constructor_s_"></a></span><a class="link" href="model_linestring.html#geometry.reference.models.model_linestring.constructor_s_">Constructor(s)</a>
        </h6>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                  <p>
                    Function
                  </p>
                </th>
<th>
                  <p>
                    Description
                  </p>
                </th>
<th>
                  <p>
                    Parameters
                  </p>
                </th>
</tr></thead>
<tbody>
<tr>
<td>
                  <p>
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">linestring</span><span class="special">()</span></pre>
<p>
                  </p>
                </td>
<td>
                  <p>
                    Default constructor, creating an empty linestring.
                  </p>
                </td>
<td>
                </td>
</tr>
<tr>
<td>
                  <p>
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">&gt;</span>
<span class="identifier">linestring</span><span class="special">(</span><span class="identifier">Iterator</span> <span class="identifier">begin</span><span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">end</span><span class="special">)</span></pre>
<p>
                  </p>
                </td>
<td>
                  <p>
                    Constructor with begin and end, filling the linestring.
                  </p>
                </td>
<td>
                  <p>
                    <span class="bold"><strong>Iterator</strong></span>: <span class="emphasis"><em>begin</em></span>:
                  </p>
                  <p>
                    <span class="bold"><strong>Iterator</strong></span>: <span class="emphasis"><em>end</em></span>:
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
</p>
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">linestring</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">initializer_list</span><span class="special">&lt;</span> <span class="identifier">Point</span> <span class="special">&gt;</span> <span class="identifier">l</span><span class="special">)</span></pre>
<p>
                  </p>
                </td>
<td>
                  <p>
                    Constructor taking std::initializer_list, filling the linestring.
                  </p>
                </td>
<td>
                  <p>
                    <span class="bold"><strong>std::initializer_list&lt; Point &gt;</strong></span>:
                    <span class="emphasis"><em>l</em></span>:
                  </p>
                </td>
</tr>
</tbody>
</table></div>
<h6>
<a name="geometry.reference.models.model_linestring.h4"></a>
          <span class="phrase"><a name="geometry.reference.models.model_linestring.header"></a></span><a class="link" href="model_linestring.html#geometry.reference.models.model_linestring.header">Header</a>
        </h6>
<p>
          Either
        </p>
<p>
          <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
        </p>
<p>
          Or
        </p>
<p>
          <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">linestring</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
        </p>
<h6>
<a name="geometry.reference.models.model_linestring.h5"></a>
          <span class="phrase"><a name="geometry.reference.models.model_linestring.examples"></a></span><a class="link" href="model_linestring.html#geometry.reference.models.model_linestring.examples">Examples</a>
        </h6>
<p>
          Declaration and use of the Boost.Geometry model::linestring, modelling
          the Linestring Concept
        </p>
<p>
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="keyword">namespace</span> <span class="identifier">bg</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">;</span>

<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
    <span class="keyword">typedef</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">point</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">cs</span><span class="special">::</span><span class="identifier">cartesian</span><span class="special">&gt;</span> <span class="identifier">point_t</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">linestring</span><span class="special">&lt;</span><span class="identifier">point_t</span><span class="special">&gt;</span> <span class="identifier">linestring_t</span><span class="special">;</span>

    <span class="identifier">linestring_t</span> <span class="identifier">ls1</span><span class="special">;</span> <a class="co" name="geometry.reference.models.model_linestring.c0" href="model_linestring.html#geometry.reference.models.model_linestring.c1"><img src="../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a>

<span class="preprocessor">#if</span> <span class="special">!</span><span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX</span><span class="special">)</span> <span class="special">\</span>
 <span class="special">&amp;&amp;</span> <span class="special">!</span><span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_NO_CXX11_HDR_INITIALIZER_LIST</span><span class="special">)</span>

    <span class="identifier">linestring_t</span> <span class="identifier">ls2</span><span class="special">{{</span><span class="number">0.0</span><span class="special">,</span> <span class="number">0.0</span><span class="special">},</span> <span class="special">{</span><span class="number">1.0</span><span class="special">,</span> <span class="number">0.0</span><span class="special">},</span> <span class="special">{</span><span class="number">1.0</span><span class="special">,</span> <span class="number">2.0</span><span class="special">}};</span> <a class="co" name="geometry.reference.models.model_linestring.c2" href="model_linestring.html#geometry.reference.models.model_linestring.c3"><img src="../../../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a>

<span class="preprocessor">#endif</span>

    <span class="identifier">bg</span><span class="special">::</span><span class="identifier">append</span><span class="special">(</span><span class="identifier">ls1</span><span class="special">,</span> <span class="identifier">point_t</span><span class="special">(</span><span class="number">0.0</span><span class="special">,</span> <span class="number">0.0</span><span class="special">));</span> <a class="co" name="geometry.reference.models.model_linestring.c4" href="model_linestring.html#geometry.reference.models.model_linestring.c5"><img src="../../../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a>
    <span class="identifier">bg</span><span class="special">::</span><span class="identifier">append</span><span class="special">(</span><span class="identifier">ls1</span><span class="special">,</span> <span class="identifier">point_t</span><span class="special">(</span><span class="number">1.0</span><span class="special">,</span> <span class="number">0.0</span><span class="special">));</span>
    <span class="identifier">bg</span><span class="special">::</span><span class="identifier">append</span><span class="special">(</span><span class="identifier">ls1</span><span class="special">,</span> <span class="identifier">point_t</span><span class="special">(</span><span class="number">1.0</span><span class="special">,</span> <span class="number">2.0</span><span class="special">));</span>

    <span class="keyword">double</span> <span class="identifier">l</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">length</span><span class="special">(</span><span class="identifier">ls1</span><span class="special">);</span>

    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">l</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>

    <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
        </p>
<div class="calloutlist"><table border="0" summary="Callout list">
<tr>
<td width="5%" valign="top" align="left"><p><a name="geometry.reference.models.model_linestring.c1"></a><a href="#geometry.reference.models.model_linestring.c0"><img src="../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td>
<td valign="top" align="left"><p>
              Default-construct a linestring.
            </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a name="geometry.reference.models.model_linestring.c3"></a><a href="#geometry.reference.models.model_linestring.c2"><img src="../../../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a> </p></td>
<td valign="top" align="left"><p>
              Construct a linestring containing three points, using C++11 unified
              initialization syntax.
            </p></td>
</tr>
<tr>
<td width="5%" valign="top" align="left"><p><a name="geometry.reference.models.model_linestring.c5"></a><a href="#geometry.reference.models.model_linestring.c4"><img src="../../../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a> </p></td>
<td valign="top" align="left"><p>
              Append point.
            </p></td>
</tr>
</table></div>
<p>
          Output:
        </p>
<pre class="programlisting">3
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2009-2021 Barend Gehrels,
      Bruno Lalande, Mateusz Loskot, Adam Wulkiewicz, Oracle and/or its affiliates<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="model_d3_point_xyz.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../models.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="model_polygon.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
